import state from './model';

import handle from './reducer';

import React, { Component } from 'react';

let Control = Module=> {
    return class extends Component {
        constructor(props) {
            super(props);
            this.state = {
                ...state
            }
        }

        dispatch(type, params) {
            let state = handle[type](this.state, params);
            this.setState({
                ...state
            });
        }

        addItem = ()=> {
            let id = this.state.list.length + 1;
            this.dispatch('addItem', {
                id: id,
                name: 'aaa' + id
            })
        }

        render() {
            return <Module
                {...this.props}
                {...this.state}
                addItem={this.addItem}
                />
        }

    }
}


export default Control;